package com.yonyou.crm.base.industry.ctrl;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.crm.base.industry.entity.IndustryVO;
import com.yonyou.crm.base.industry.rmitf.IIndustryRmService;
import com.yonyou.crm.common.exception.CrmMessageException;
import com.yonyou.crm.common.rest.util.RequestUtil;
import com.yonyou.crm.common.rest.util.ResponseUtil;

@RestController
@RequestMapping(value = "/base/industrys")
public class IndustryCtrl{
	@Autowired
	private IIndustryRmService service;
	
	@RequestMapping(value = "reftree", method = RequestMethod.GET)
	public Object getRefTree(HttpServletRequest request, HttpServletResponse response) {
		List<Map<String, Object>> tree = service.getRefTree();
		JSONObject result = new JSONObject();
		result.put("data", tree);
		return ResponseUtil.getObject(result);
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public Object list(HttpServletRequest request, HttpServletResponse response) throws CrmMessageException {
		JSONObject paramObj = RequestUtil.getParamObject(request);
		JSONObject result = new JSONObject();
		if (paramObj != null){
			List<IndustryVO> list = service.getList((Map<String, Object>)paramObj.get("searchMap"));
			result.put("data", list);
		}
		return ResponseUtil.getObject(result);
	}
	
}